/**
* 
* ====================================================================
*
* @author apov <apov@ymail.com>
*/ 
// DoubleQueue.h
//

#pragma once

#include "BaseDefine.h"
#include <queue>

/**
* @class DoubleQueue
*  - 
*/
template <class T>
class DoubleQueue{
	typedef std::queue<T> Q;

public:
	void flip(){
		if( producer_ == &true_ ){
			producer_ = &false_;
			consumer_ = &true_;
		}
		else{
			producer_ = &true_;
			consumer_ = &false_;
		}
	}

	T pop(){		
		T t;

		if( consumer_->size() ){
			t = consumer_->front();
			consumer_->pop();
		}
		else
			memset( &t, 0, sizeof( T ) );

		return t;
	}

	void push(T t){	
		producer_->push(t);	
	}

	size_t producer_size(){
		return producer_->size();
	}

	size_t consumer_size(){
		return consumer_->size();
	}

	size_t size(){
		return true_.size() + false_.size();
	}

	DoubleQueue(){
		producer_ = &true_;
		consumer_ = &false_;
	}

	virtual ~DoubleQueue(){
		while(! true_.empty() )
			true_.pop();

		while(! false_.empty() )
			false_.pop();
	}

protected:
	
private:
	Q* producer_;
	Q* consumer_;

	Q true_;
	Q false_;	
};
